$(function() {
  var all_url = "http://api20.scsj.net.cn";
  var id = $.cookie("userId");
  var token = $.cookie("token");

  function getUrlParams(name) {
    var search = document.location.search;
    var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
    var matcher = pattern.exec(search);
    var items = null;
    if (null != matcher) {
      try {
        items = decodeURIComponent(decodeURIComponent(matcher[1]));
      } catch (e) {
        try {
          items = decodeURIComponent(matcher[1]);
        } catch (e) {
          items = matcher[1];
        };
      };
    }
    return items;
  };

  // 获取用户索引
  var index = getUrlParams("index");

  $.ajax({
    url: all_url + '/user/userGradeDetails.do',
    type: 'post',
    dataType: 'json',
    data: {
      userId: id,
      tocken: token
    },
    success: function(data, status, xhr) {
      if (xhr.responseJSON.code == 200) {
        if (index == -1) {
          var upper = data.result.upper;
          $('.name').text(upper.user_name);
          $('.expandPhone').text(upper.phone);
          $('.expandPhone').attr("href","tel:"+upper.phone);
          
          if (upper.userPhoto) {
            $("#userPhoto").attr("src", upper.userPhoto);
          }
          $("#num").text(upper.baozhengjin_status);
          $(".date").text(upper.createTime);
        } else {
          var sounList = data.result.sounList[index];
          $('.name').text(sounList.name);
          $('.expandPhone').text(sounList.phone);
          $('.expandPhone').attr("href","tel:"+sounList.phone);
          if (sounList.userPhoto) {
            $("#userPhoto").attr("src", sounList.userPhoto);
          }
          $("#num").text(sounList.baozhengjin_status);
          $(".date").text(sounList.createTime);
        }
      }
    },
    error:function(){
      $('.main').html('<div style="text-align:center;color:red;line-height:1.33rem;color:red;height:1.33rem">获取信息错误</div>');
    }

  })
})